home *** CD-ROM | disk | FTP | other *** search
/ APDL Other Worlds / APDL Other Worlds Collection.iso / SF3000 / Extras / !SFtoSpr / c / SFMenu < prev    next >
Encoding:
Text File  |  2003-11-06  |  3.7 KB  |  116 lines

  1. /*
  2.  *  SFtoSpr - Star Fighter 3000 graphics converter
  3.  *  Iconbar menu
  4.  *  Copyright (C) 2000  Chris Bazley
  5.  *
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public Licence as published by
  8.  *  the Free Software Foundation; either version 2 of the Licence, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public Licence for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public Licence
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /* ANSI library files */
  22. #include <stdlib.h>
  23.  
  24. /* RISC OS library files */
  25. #include "kernel.h"
  26. #include "toolbox.h"
  27. #include "event.h"
  28. #include "menu.h"
  29. #include "saveas.h"
  30.  
  31. /* My library files */
  32. #include "err.h"
  33. #include "Macros.h"
  34. #include "Loader.h"
  35. #include "ViewsMenu.h"
  36.  
  37. /* Local headers */
  38. #include "SFmenu.h"
  39. #include "PreQuit.h"
  40. #include "Main.h"
  41.  
  42. /* Item IDs */
  43. #define MENU_HELP  0
  44. #define MENU_QUIT  2
  45. #define MENU_VIEWS 3
  46. #define MENU_MULTI 4
  47.  
  48. /* ----------------------------------------------------------------------- */
  49. /*                       Function prototypes                               */
  50.  
  51. static ToolboxEventHandler _Menu_selecthandler, _Menu_showhandler;
  52.  
  53. /* ----------------------------------------------------------------------- */
  54. /*                         Public functions                                */
  55.  
  56. void Menu_initialise(ObjectId id)
  57. {
  58.   /* Listen for selections */
  59.   EF(event_register_toolbox_handler(id, Menu_Selection, _Menu_selecthandler, 0));
  60.   EF(event_register_toolbox_handler(id, Menu_AboutToBeShown, _Menu_showhandler, 0));
  61.   EF(ViewsMenu_parentcreated(id, MENU_VIEWS));
  62. }
  63.  
  64.  
  65. /* ----------------------------------------------------------------------- */
  66. /*                         Private functions                               */
  67.  
  68. static int _Menu_showhandler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
  69. {
  70.   RE(menu_set_tick(0, id_block->self_id, MENU_MULTI, (int)multi_saveboxes));
  71.   
  72.   return 0; /* pass event on (to ViewsMenu) */
  73. }
  74.  
  75. /* ----------------------------------------------------------------------- */
  76.  
  77. static int _Menu_selecthandler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
  78. {
  79.   /* Handle click on icon bar menu */
  80.   ObjectId editingwindow;
  81.   ObjectClass object_class;
  82.   
  83.   switch(id_block->self_component) {
  84.     case MENU_MULTI:
  85.       /* Update menu entry tick (doesn't do it automatically!) */ 
  86.       multi_saveboxes = !multi_saveboxes;
  87.       RE(menu_set_tick(0, id_block->self_id, MENU_MULTI, (int)multi_saveboxes));
  88.  
  89.       if(!multi_saveboxes) {
  90.         /* Remove all pre-existing saveboxes */
  91.         editingwindow = ViewMenu_getfirst();
  92.         while(editingwindow != NULL_ObjectId) {
  93.           RE(toolbox_get_object_class(0, editingwindow, &object_class));
  94.           if(object_class == SaveAs_ObjectClass && editingwindow != last_savebox)
  95.             RE(toolbox_delete_object(0, editingwindow));
  96.             
  97.           editingwindow = ViewMenu_getnext(editingwindow);
  98.         }
  99.       }
  100.       return 1; /* claim event */
  101.       
  102.     case MENU_HELP:
  103.       /* load help */
  104.       if(_kernel_oscli("Filer_Run SFtoSprRes:Help") == _kernel_ERROR)
  105.         err_check_rep(_kernel_last_oserror());
  106.       return 1; /* claim event */
  107.       
  108.     case MENU_QUIT:
  109.       /* quit program */
  110.       if(TRY_QUIT(0))
  111.         exit(EXIT_SUCCESS); /* safe to quit */
  112.       return 1; /* claim event */
  113.   }
  114.   return 0; /* not handled */
  115. }
  116.